﻿-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Ivy_Flat_Insert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [Ivy_Flat_Insert]
GO



CREATE PROCEDURE [Ivy_Flat_Insert] 
-- =============================================
-- Author:		<Sagar sk>
-- Create date: <12/08/2014>
-- Description:	<Ivy_Flat_Insert>
-- Modified by:		<Mrinmoy Das>
-- Modified date:	<27/10/2014>
-- =============================================

-- Add the parameters for the stored procedure here
	(
	            @FlatSocietyKey int = NULL,
				@FlatNumber varchar(50),
				@FlatFloorNumber varchar(50),
				@FlatType varchar(50),
				@FlatBlockName varchar(50),
				@FlatOccupancy int,
				@FlatNumberOfBedrooms int,
				@FlatNumberOfKitchen int,
				@FlatNumberOfToilets int,
				@FlatNumberOfLivingroom int,
				@FlatNumberOfStudyroom int,
				@FlatNumberOfBalcony int,
				@FlatTotalArea int,
				@FlatNumberOfWaterInlet int,
				

				
				@Sys_CreatedByID varchar(50)= NULL,
				@Sys_ModifiedByID varchar(50) = NULL,
				@Sys_DeleteType int = 0,
				@Sys_OrganizationID int = NULL,
				@Sys_InitialPrimaryKeys varchar(max)= NULL,
				@Sys_WorkstationName varchar(50)= NULL,
				
				@Sys_DateOfCreation datetime OUTPUT,
				@FlatKey int OUTPUT
	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;

	IF @Sys_WorkstationName = 'Default'	
	BEGIN
		SET @Sys_WorkstationName = (SELECT @@SERVERNAME);
	END
	DECLARE @CurrentDataTime datetime;
	SET @CurrentDataTime = GETDATE();
	
    INSERT INTO [Flat]
           (	
		        [FlatSocietyKey],
				[FlatNumber],
				[FlatFloorNumber],
				[FlatType],
				[FlatBlockName],
				[FlatOccupancy],
				[FlatNumberOfBedrooms],
				[FlatNumberOfKitchen],
				[FlatNumberOfToilets],
				[FlatNumberOfLivingroom],
				[FlatNumberOfStudyroom],
				[FlatNumberOfBalcony],
				[FlatTotalArea],
				[FlatNumberOfWaterInlet],
				[Sys_DateOfCreation],
				[Sys_DateOfModification],
				[Sys_CreatedByID],
				[Sys_ModifiedByID],
				[Sys_DeleteType],
				[Sys_IsDeleted],
				[Sys_OrganizationID],
				[Sys_InitialPrimaryKeys],
				[Sys_WorkstationName]
			)
     VALUES
           (
		        @FlatSocietyKey,
				@FlatNumber,
				@FlatFloorNumber,
				@FlatType,
				@FlatBlockName,
				@FlatOccupancy,
				@FlatNumberOfBedrooms,
				@FlatNumberOfKitchen,
				@FlatNumberOfToilets,
				@FlatNumberOfLivingroom,
				@FlatNumberOfStudyroom,
				@FlatNumberOfBalcony,
				@FlatTotalArea,
				@FlatNumberOfWaterInlet,
				@CurrentDataTime,
				@CurrentDataTime,
				@Sys_CreatedByID,
				@Sys_ModifiedByID,
				@Sys_DeleteType,
				0,
				@Sys_OrganizationID,
				@Sys_InitialPrimaryKeys,
				@Sys_WorkstationName
			);
	SET @FlatKey = SCOPE_IDENTITY();
	SET @Sys_DateOfCreation = @CurrentDataTime;
END



GO


